package com.xingkeduo.business.operation.domain;

import com.xingkeduo.business.operation.service.ShopsDaysService;
import com.xingkeduo.pojo.query.ShopsDaysQuery;
import com.xingkeduo.pojo.table.ShopsDaysTable;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.DataException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商户domain
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class ShopsDaysDomain {

    @Autowired
    private ShopsDaysService shopsDaysService;

    public ShopsDaysTable getShopsDaysByCode(Long code) throws Throwable {

        ShopsDaysTable shopsDaysTable = shopsDaysService.selectByCode(code);

        return shopsDaysTable;
    }
    /**
     * 根据店铺查询店铺时间详情
     */
    public List<ShopsDaysTable> getShopsDaysList(ShopsDaysQuery shopsDaysQuery) throws Throwable {

        List<ShopsDaysTable> shopsDaysList = shopsDaysService.selectLists(shopsDaysQuery);

        return shopsDaysList;
    }

    public int createShopsDays(ShopsDaysTable shopsDaysTable) throws Throwable {
        return shopsDaysService.insert(shopsDaysTable);
    }

    public int modifyShopsDays(ShopsDaysTable shopsDaysTable) throws Throwable {
        return shopsDaysService.update(shopsDaysTable);
    }

    //删除
    public int delShopsDays(Long code) throws Throwable {
        ShopsDaysTable shopsDaysTable = new ShopsDaysTable();
        shopsDaysTable.setCode(code);
        shopsDaysTable.setIsDelete(YesNoEnum.YES);
        int delRes = shopsDaysService.delete(shopsDaysTable);
        if(delRes > 0){
            return delRes;
        }else{
            throw new DataException(DataException.Type.FAIL, "删除失败");
        }
    }

}
